#include <iostream>
#include "message.hpp"

struct SyncMessage : public BaseMessage<SyncMessage>
{
    SyncMessage() { std::cout << "SyncMessage()" << std::endl; }
    ~SyncMessage() { std::cout << "~SyncMessage()" << std::endl; }
    std::string name;
    int age;
};

struct AsynMessgae : public BaseMessage<AsynMessgae>
{
    AsynMessgae() { std::cout << "AsynMessgae()" << std::endl; }
    ~AsynMessgae() { std::cout << "~AsynMessgae()" << std::endl; }
    std::string name;
    int age;
};


class Recevicer : public BaseHandle<SyncMessage>
                , public BaseHandle<AsynMessgae>
{
public:
    Recevicer() { std::cout << "Recevicer()" << std::endl; }
    ~Recevicer() { std::cout << "~Recevicer()" << std::endl; }
    virtual bool handle(const SyncMessage *pMsg)
    {
        if(pMsg == nullptr)
            return false;
        std::cout << "SyncMessage ==> name: " << pMsg->name << ", age: " << pMsg->age << std::endl;
        return true;
    }
    virtual bool handle(const AsynMessgae *pMsg)
    {
        if(pMsg == nullptr) {
            std::cout << "AsynMessgae ===> pMsg is nullptr......\n";
            return false;
        }
        std::cout << "AsynMessgae ==> name: " << pMsg->name << ", age: " << pMsg->age << std::endl;
        return true;
    }
};

int main()
{
    Recevicer recv;
    AsynMessgae aMsg;
    aMsg.name = "lijiangjun";
    aMsg.age = 17;
    aMsg.post();
    SyncMessage msg;
    msg.name = "ljj";
    msg.age = 18;
    msg.send();
    
    std::this_thread::sleep_for(std::chrono::microseconds(150));
    return 0;
}